<?php

namespace app\store\model;

use think\Model;

class TradeAmountModel extends Model
{
    protected $connection = 'db_platform_operatelog';

    protected $table = 'game_trade_amount_distribution';

    // 等级与数据库中的level保持对应
    const TRADE_AMOUNT = [
        1 => '1-99',
        2 => '100-499',
        3 => '500-999',
        4 => '1000-4999',
        5 => '5000-9999',
        6 => '10000以上'
    ];

    /**
     * @param $where
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getTradeAmountByDate($where)
    {
        $data = self::where($where)
            ->fieldRaw('amount_dist,sum(num) as amount_num,sum(count) as amount_count,sum(amount) as all_amount,round(avg(amount_rate),4) as amount_rate')
            ->group('amount_dist')
            ->select();

        return $data;
    }
}